package ru.st.selenium.applogic2;

import java.util.List;

import org.openqa.selenium.Alert;

import ru.st.selenium.applogic.FilmHelper;
import ru.st.selenium.model.Film;
import ru.st.selenium.pages.PageManager;

public class FilmHelper2 extends DriverBasedHelper implements FilmHelper {

	public FilmHelper2(ApplicationManager2 manager) {
		super(manager.getWebDriver());
	}

	@Override
	public void create(Film film) {
		pages.homePage.clickAddButton();
		pages.addFilmPage.setTitle(film.getTitle()).setYear(film.getYear())
				.clickSaveButton();
	}

	@Override
	public void delete(Film film) {
		pages.homePage.chooseFilmInList();
		pages.filmInfoPage.removeButtonClick();
		 Alert alert = driver.switchTo().alert();
		 alert.accept();
	}

	@Override
	public List<Film> search(String title) {
		pages.homePage.enterKeyword(title);
		return pages.homePage.getFilms();
	}

	@Override
	public PageManager getPageManager() {
		return pages;
	}
}
